﻿using System.Collections.Generic;
using System.Linq;

namespace Entities.Enumeration {

    public class Courier {

        public string Name    { get; private set; }
        public string CName   { get; private set; }
        public int Code       { get; private set; }

        public readonly static Courier EverFast   = new Courier("Ever Fast",   "EWE",    100);
        public readonly static Courier OneExpress = new Courier("One Express", "壹速递",   200);
        public readonly static Courier AuPost     = new Courier("AuPost",      "澳洲邮政", 300);
        public readonly static Courier AuExpress  = new Courier("AuExpress",   "中邮",    500);
        public readonly static Courier Other      = new Courier("Other",       "其他",    999);

        public readonly static List<Courier> All = new List<Courier> {
            EverFast,OneExpress,AuPost,AuExpress,Other
        };

        public readonly static Dictionary<string, Courier> NameIndex = All.ToDictionary(item => item.Name);
        public readonly static Dictionary<int, Courier>    CodeIndex = All.ToDictionary(item => item.Code);

        public Courier(string name, string cname, int code) {
            Name  = name;
            CName = cname;
            Code  = code;
        }

        public static string GetName(int code) {
            return CodeIndex[code] == null?  Other.Name : CodeIndex[code].Name;
        }

        public static Courier GetInstance(string name) {
            return NameIndex[name] ?? Other;
        }

        public static Courier GetInstance(int code) {
            return CodeIndex[code] ?? Other;
        }

    }

}